import axios from "axios";

const typeBaseUrl= "http://localhost:8082";
const typeRequest={
    loadTypes(type,callBack){
        let url = typeBaseUrl + "/type/list?";
        if(type){
            if(type.typeEncode){
                url += "&typeEncode=" + type.typeEncode;
            }
            if(type.typeName){
                url += "&typeName=" + type.typeName;
            }
            if(type.typeType){
                url += "&typeType=" + type.typeType;
            }
        }
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    insertType(type,callBack){
        let url = typeBaseUrl + "/type/insert";
        axios.post(url,type)
            .then(res=>{
                callBack(res.data);
            })
    },
    update(type,callBack){
        let url  = typeBaseUrl + "/type/update";
        axios.put(url,type)
            .then(res=>{
                callBack(res.data);
            })
    },
    selectById(typeId,callBack){
        let url = typeBaseUrl + "/type/selectById?typeId=" + typeId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    delete(typeId,callBack){
        let url = typeBaseUrl + "/type/delete?typeId=" + typeId;
        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    }
}

export default typeRequest;
